Public Class frmEditFactions
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlFactionOneProperties As System.Windows.Forms.Panel
    Friend WithEvents txtFactionOneName As System.Windows.Forms.TextBox
    Friend WithEvents txtFactionOnePoints As System.Windows.Forms.TextBox
    Friend WithEvents lblFactionOneName As System.Windows.Forms.Label
    Friend WithEvents lblFactionOnePoints As System.Windows.Forms.Label
    Friend WithEvents lblFactionTwoName As System.Windows.Forms.Label
    Friend WithEvents txtFactionTwoName As System.Windows.Forms.TextBox
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents pnlTopBorder As System.Windows.Forms.Panel
    Friend WithEvents picCampaignerIcon As System.Windows.Forms.PictureBox
    Friend WithEvents txtTitleBox As System.Windows.Forms.TextBox
    Friend WithEvents pnlFactionTwo As System.Windows.Forms.Panel
    Friend WithEvents lblFactionOneDeployedPoints As System.Windows.Forms.Label
    Friend WithEvents txtFactionOneDeployedPoints As System.Windows.Forms.TextBox
    Friend WithEvents lblFactionOneReservePoints As System.Windows.Forms.Label
    Friend WithEvents lblFactionTwoReservePoints As System.Windows.Forms.Label
    Friend WithEvents txtFactionTwoReservePoints As System.Windows.Forms.TextBox
    Friend WithEvents lblFactionTwoDeployedPoints As System.Windows.Forms.Label
    Friend WithEvents txtFactionTwoDeployedPoints As System.Windows.Forms.TextBox
    Friend WithEvents lblFactionTwoPoints As System.Windows.Forms.Label
    Friend WithEvents txtFactionTwoPoints As System.Windows.Forms.TextBox
    Friend WithEvents txtFactionOneReservePoints As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmEditFactions))
        Me.pnlFactionOneProperties = New System.Windows.Forms.Panel
        Me.lblFactionOneReservePoints = New System.Windows.Forms.Label
        Me.txtFactionOneReservePoints = New System.Windows.Forms.TextBox
        Me.lblFactionOneDeployedPoints = New System.Windows.Forms.Label
        Me.txtFactionOneDeployedPoints = New System.Windows.Forms.TextBox
        Me.lblFactionOnePoints = New System.Windows.Forms.Label
        Me.lblFactionOneName = New System.Windows.Forms.Label
        Me.txtFactionOnePoints = New System.Windows.Forms.TextBox
        Me.txtFactionOneName = New System.Windows.Forms.TextBox
        Me.pnlFactionTwo = New System.Windows.Forms.Panel
        Me.lblFactionTwoReservePoints = New System.Windows.Forms.Label
        Me.txtFactionTwoReservePoints = New System.Windows.Forms.TextBox
        Me.lblFactionTwoDeployedPoints = New System.Windows.Forms.Label
        Me.txtFactionTwoDeployedPoints = New System.Windows.Forms.TextBox
        Me.lblFactionTwoPoints = New System.Windows.Forms.Label
        Me.txtFactionTwoPoints = New System.Windows.Forms.TextBox
        Me.lblFactionTwoName = New System.Windows.Forms.Label
        Me.txtFactionTwoName = New System.Windows.Forms.TextBox
        Me.btnOK = New System.Windows.Forms.Button
        Me.pnlTopBorder = New System.Windows.Forms.Panel
        Me.picCampaignerIcon = New System.Windows.Forms.PictureBox
        Me.txtTitleBox = New System.Windows.Forms.TextBox
        Me.pnlFactionOneProperties.SuspendLayout()
        Me.pnlFactionTwo.SuspendLayout()
        Me.pnlTopBorder.SuspendLayout()
        CType(Me.picCampaignerIcon, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'pnlFactionOneProperties
        '
        Me.pnlFactionOneProperties.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlFactionOneProperties.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlFactionOneProperties.Controls.Add(Me.lblFactionOneReservePoints)
        Me.pnlFactionOneProperties.Controls.Add(Me.txtFactionOneReservePoints)
        Me.pnlFactionOneProperties.Controls.Add(Me.lblFactionOneDeployedPoints)
        Me.pnlFactionOneProperties.Controls.Add(Me.txtFactionOneDeployedPoints)
        Me.pnlFactionOneProperties.Controls.Add(Me.lblFactionOnePoints)
        Me.pnlFactionOneProperties.Controls.Add(Me.lblFactionOneName)
        Me.pnlFactionOneProperties.Controls.Add(Me.txtFactionOnePoints)
        Me.pnlFactionOneProperties.Controls.Add(Me.txtFactionOneName)
        Me.pnlFactionOneProperties.Location = New System.Drawing.Point(8, 48)
        Me.pnlFactionOneProperties.Name = "pnlFactionOneProperties"
        Me.pnlFactionOneProperties.Size = New System.Drawing.Size(248, 192)
        Me.pnlFactionOneProperties.TabIndex = 2
        '
        'lblFactionOneReservePoints
        '
        Me.lblFactionOneReservePoints.Location = New System.Drawing.Point(16, 154)
        Me.lblFactionOneReservePoints.Name = "lblFactionOneReservePoints"
        Me.lblFactionOneReservePoints.Size = New System.Drawing.Size(96, 24)
        Me.lblFactionOneReservePoints.TabIndex = 8
        Me.lblFactionOneReservePoints.Text = "Reserve Points"
        '
        'txtFactionOneReservePoints
        '
        Me.txtFactionOneReservePoints.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtFactionOneReservePoints.Location = New System.Drawing.Point(120, 154)
        Me.txtFactionOneReservePoints.Name = "txtFactionOneReservePoints"
        Me.txtFactionOneReservePoints.ReadOnly = True
        Me.txtFactionOneReservePoints.Size = New System.Drawing.Size(112, 20)
        Me.txtFactionOneReservePoints.TabIndex = 7
        Me.txtFactionOneReservePoints.Text = "0"
        Me.txtFactionOneReservePoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblFactionOneDeployedPoints
        '
        Me.lblFactionOneDeployedPoints.Location = New System.Drawing.Point(15, 116)
        Me.lblFactionOneDeployedPoints.Name = "lblFactionOneDeployedPoints"
        Me.lblFactionOneDeployedPoints.Size = New System.Drawing.Size(97, 24)
        Me.lblFactionOneDeployedPoints.TabIndex = 6
        Me.lblFactionOneDeployedPoints.Text = "Deployed Points"
        '
        'txtFactionOneDeployedPoints
        '
        Me.txtFactionOneDeployedPoints.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtFactionOneDeployedPoints.Location = New System.Drawing.Point(120, 114)
        Me.txtFactionOneDeployedPoints.Name = "txtFactionOneDeployedPoints"
        Me.txtFactionOneDeployedPoints.ReadOnly = True
        Me.txtFactionOneDeployedPoints.Size = New System.Drawing.Size(112, 20)
        Me.txtFactionOneDeployedPoints.TabIndex = 5
        Me.txtFactionOneDeployedPoints.Text = "0"
        Me.txtFactionOneDeployedPoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblFactionOnePoints
        '
        Me.lblFactionOnePoints.Location = New System.Drawing.Point(16, 74)
        Me.lblFactionOnePoints.Name = "lblFactionOnePoints"
        Me.lblFactionOnePoints.Size = New System.Drawing.Size(96, 24)
        Me.lblFactionOnePoints.TabIndex = 4
        Me.lblFactionOnePoints.Text = "Total Point Value"
        '
        'lblFactionOneName
        '
        Me.lblFactionOneName.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblFactionOneName.Location = New System.Drawing.Point(16, 8)
        Me.lblFactionOneName.Name = "lblFactionOneName"
        Me.lblFactionOneName.Size = New System.Drawing.Size(216, 24)
        Me.lblFactionOneName.TabIndex = 3
        Me.lblFactionOneName.Text = "Side One Faction Name"
        '
        'txtFactionOnePoints
        '
        Me.txtFactionOnePoints.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtFactionOnePoints.Location = New System.Drawing.Point(120, 72)
        Me.txtFactionOnePoints.Name = "txtFactionOnePoints"
        Me.txtFactionOnePoints.Size = New System.Drawing.Size(112, 20)
        Me.txtFactionOnePoints.TabIndex = 1
        Me.txtFactionOnePoints.Text = "0"
        Me.txtFactionOnePoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'txtFactionOneName
        '
        Me.txtFactionOneName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtFactionOneName.Location = New System.Drawing.Point(16, 32)
        Me.txtFactionOneName.Name = "txtFactionOneName"
        Me.txtFactionOneName.ReadOnly = True
        Me.txtFactionOneName.Size = New System.Drawing.Size(216, 20)
        Me.txtFactionOneName.TabIndex = 0
        Me.txtFactionOneName.Text = "Side One"
        '
        'pnlFactionTwo
        '
        Me.pnlFactionTwo.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlFactionTwo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlFactionTwo.Controls.Add(Me.lblFactionTwoReservePoints)
        Me.pnlFactionTwo.Controls.Add(Me.txtFactionTwoReservePoints)
        Me.pnlFactionTwo.Controls.Add(Me.lblFactionTwoDeployedPoints)
        Me.pnlFactionTwo.Controls.Add(Me.txtFactionTwoDeployedPoints)
        Me.pnlFactionTwo.Controls.Add(Me.lblFactionTwoPoints)
        Me.pnlFactionTwo.Controls.Add(Me.txtFactionTwoPoints)
        Me.pnlFactionTwo.Controls.Add(Me.lblFactionTwoName)
        Me.pnlFactionTwo.Controls.Add(Me.txtFactionTwoName)
        Me.pnlFactionTwo.Location = New System.Drawing.Point(264, 48)
        Me.pnlFactionTwo.Name = "pnlFactionTwo"
        Me.pnlFactionTwo.Size = New System.Drawing.Size(248, 192)
        Me.pnlFactionTwo.TabIndex = 3
        '
        'lblFactionTwoReservePoints
        '
        Me.lblFactionTwoReservePoints.Location = New System.Drawing.Point(16, 156)
        Me.lblFactionTwoReservePoints.Name = "lblFactionTwoReservePoints"
        Me.lblFactionTwoReservePoints.Size = New System.Drawing.Size(96, 24)
        Me.lblFactionTwoReservePoints.TabIndex = 14
        Me.lblFactionTwoReservePoints.Text = "Reserve Points"
        '
        'txtFactionTwoReservePoints
        '
        Me.txtFactionTwoReservePoints.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtFactionTwoReservePoints.Location = New System.Drawing.Point(120, 156)
        Me.txtFactionTwoReservePoints.Name = "txtFactionTwoReservePoints"
        Me.txtFactionTwoReservePoints.ReadOnly = True
        Me.txtFactionTwoReservePoints.Size = New System.Drawing.Size(112, 20)
        Me.txtFactionTwoReservePoints.TabIndex = 13
        Me.txtFactionTwoReservePoints.Text = "0"
        Me.txtFactionTwoReservePoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblFactionTwoDeployedPoints
        '
        Me.lblFactionTwoDeployedPoints.Location = New System.Drawing.Point(15, 118)
        Me.lblFactionTwoDeployedPoints.Name = "lblFactionTwoDeployedPoints"
        Me.lblFactionTwoDeployedPoints.Size = New System.Drawing.Size(97, 24)
        Me.lblFactionTwoDeployedPoints.TabIndex = 12
        Me.lblFactionTwoDeployedPoints.Text = "Deployed Points"
        '
        'txtFactionTwoDeployedPoints
        '
        Me.txtFactionTwoDeployedPoints.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtFactionTwoDeployedPoints.Location = New System.Drawing.Point(120, 116)
        Me.txtFactionTwoDeployedPoints.Name = "txtFactionTwoDeployedPoints"
        Me.txtFactionTwoDeployedPoints.ReadOnly = True
        Me.txtFactionTwoDeployedPoints.Size = New System.Drawing.Size(112, 20)
        Me.txtFactionTwoDeployedPoints.TabIndex = 11
        Me.txtFactionTwoDeployedPoints.Text = "0"
        Me.txtFactionTwoDeployedPoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblFactionTwoPoints
        '
        Me.lblFactionTwoPoints.Location = New System.Drawing.Point(16, 76)
        Me.lblFactionTwoPoints.Name = "lblFactionTwoPoints"
        Me.lblFactionTwoPoints.Size = New System.Drawing.Size(96, 24)
        Me.lblFactionTwoPoints.TabIndex = 10
        Me.lblFactionTwoPoints.Text = "Total Point Value"
        '
        'txtFactionTwoPoints
        '
        Me.txtFactionTwoPoints.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtFactionTwoPoints.Location = New System.Drawing.Point(120, 74)
        Me.txtFactionTwoPoints.Name = "txtFactionTwoPoints"
        Me.txtFactionTwoPoints.Size = New System.Drawing.Size(112, 20)
        Me.txtFactionTwoPoints.TabIndex = 9
        Me.txtFactionTwoPoints.Text = "0"
        Me.txtFactionTwoPoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblFactionTwoName
        '
        Me.lblFactionTwoName.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblFactionTwoName.Location = New System.Drawing.Point(16, 8)
        Me.lblFactionTwoName.Name = "lblFactionTwoName"
        Me.lblFactionTwoName.Size = New System.Drawing.Size(216, 24)
        Me.lblFactionTwoName.TabIndex = 3
        Me.lblFactionTwoName.Text = "Side Two Faction Name"
        '
        'txtFactionTwoName
        '
        Me.txtFactionTwoName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtFactionTwoName.Location = New System.Drawing.Point(16, 32)
        Me.txtFactionTwoName.Name = "txtFactionTwoName"
        Me.txtFactionTwoName.ReadOnly = True
        Me.txtFactionTwoName.Size = New System.Drawing.Size(216, 20)
        Me.txtFactionTwoName.TabIndex = 3
        Me.txtFactionTwoName.Text = "Side Two"
        '
        'btnOK
        '
        Me.btnOK.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(432, 248)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 6
        Me.btnOK.Text = "OK"
        Me.btnOK.UseVisualStyleBackColor = False
        '
        'pnlTopBorder
        '
        Me.pnlTopBorder.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlTopBorder.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlTopBorder.Controls.Add(Me.picCampaignerIcon)
        Me.pnlTopBorder.Controls.Add(Me.txtTitleBox)
        Me.pnlTopBorder.Location = New System.Drawing.Point(0, 0)
        Me.pnlTopBorder.Name = "pnlTopBorder"
        Me.pnlTopBorder.Size = New System.Drawing.Size(520, 40)
        Me.pnlTopBorder.TabIndex = 14
        '
        'picCampaignerIcon
        '
        Me.picCampaignerIcon.Image = CType(resources.GetObject("picCampaignerIcon.Image"), System.Drawing.Image)
        Me.picCampaignerIcon.Location = New System.Drawing.Point(9, 11)
        Me.picCampaignerIcon.Name = "picCampaignerIcon"
        Me.picCampaignerIcon.Size = New System.Drawing.Size(16, 16)
        Me.picCampaignerIcon.TabIndex = 9
        Me.picCampaignerIcon.TabStop = False
        '
        'txtTitleBox
        '
        Me.txtTitleBox.BackColor = System.Drawing.Color.SteelBlue
        Me.txtTitleBox.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.txtTitleBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTitleBox.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.txtTitleBox.Location = New System.Drawing.Point(32, 8)
        Me.txtTitleBox.Multiline = True
        Me.txtTitleBox.Name = "txtTitleBox"
        Me.txtTitleBox.ReadOnly = True
        Me.txtTitleBox.Size = New System.Drawing.Size(312, 26)
        Me.txtTitleBox.TabIndex = 8
        Me.txtTitleBox.Text = "Campaigner [Factions]"
        '
        'frmEditFactions
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Black
        Me.ClientSize = New System.Drawing.Size(520, 280)
        Me.Controls.Add(Me.pnlTopBorder)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.pnlFactionTwo)
        Me.Controls.Add(Me.pnlFactionOneProperties)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "frmEditFactions"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.pnlFactionOneProperties.ResumeLayout(False)
        Me.pnlFactionOneProperties.PerformLayout()
        Me.pnlFactionTwo.ResumeLayout(False)
        Me.pnlFactionTwo.PerformLayout()
        Me.pnlTopBorder.ResumeLayout(False)
        Me.pnlTopBorder.PerformLayout()
        CType(Me.picCampaignerIcon, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private ptrFactions As cmplib01.Factions
    Private ptrFactOne As cmplib01.Faction
    Private ptrFactTwo As cmplib01.Faction

    Public Sub New(ByRef facts As cmplib01.Factions)
        ' in the current version, there are two factions, one and two that are automatically created. We'll use the first
        ' two factions found until an update comes in the future... maybe.
        Me.New()
        ptrFactions = facts

        Dim de As DictionaryEntry
        Dim sKey As String
        Dim i As Int16

        For Each de In ptrFactions.HT
            sKey = de.Key.ToString
            If i = 0 Then
                ptrFactOne = ptrFactions.HT.Item(sKey)
                i = 1
            Else
                ptrFactTwo = ptrFactions.HT.Item(sKey)
                Exit For
            End If
        Next

        PopulateProperties()

    End Sub

    Private Sub PopulateProperties()
        txtFactionOneName.Text = ptrFactOne.FactionName
        txtFactionOnePoints.Text = ptrFactOne.FactionTotalPoints
        txtFactionOneDeployedPoints.Text = ptrFactOne.FactionDeployedPoints
        txtFactionOneReservePoints.Text = ptrFactOne.FactionFreePoints

        txtFactionTwoName.Text = ptrFactTwo.FactionName
        txtFactionTwoPoints.Text = ptrFactTwo.FactionTotalPoints
        txtFactionTwoDeployedPoints.Text = ptrFactTwo.FactionDeployedPoints
        txtFactionTwoReservePoints.Text = ptrFactTwo.FactionFreePoints
    End Sub

    Private Function SaveProperties() As Boolean
        Dim res As Boolean = True

        ' there is only one item that can be changed here, which is free points.
        Dim factionOnePoints As Int16
        Dim factionTwoPoints As Int16
        Try
            factionOnePoints = CInt(txtFactionOnePoints.Text)
            If factionOnePoints < ptrFactOne.FactionDeployedPoints Then
                factionOnePoints = ptrFactOne.FactionDeployedPoints
            Else
                ' go ahead and change it
                ptrFactOne.FactionTotalPoints = factionOnePoints
            End If
            factionTwoPoints = CInt(txtFactionTwoPoints.Text)
            If factionTwoPoints < ptrFactTwo.FactionDeployedPoints Then
                factionTwoPoints = ptrFactTwo.FactionDeployedPoints
            Else
                ' go ahead and change it
                ptrFactTwo.FactionTotalPoints = factionTwoPoints
            End If
            res = True
        Catch
            ' no change
            res = False
        End Try

        Return res

    End Function

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If SaveProperties() = True Then
            Me.Hide()
        Else
            MsgBox("Total point value must be greater than deployed amount.", MsgBoxStyle.Exclamation, "Invalid Property")
        End If
    End Sub

End Class
